home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Networking / GetPPPStatus / sources / TrapUtils.c < prev   
Encoding:
Text File  |  1998-02-06  |  2.6 KB  |  119 lines  |  [TEXT/CWIE]

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Functions to help you when you are building and sending Apple events.
  5. **
  6. **    by Pete Gontier, Apple Developer Technical Support
  7. **
  8. **    File:        TrapUtils.c 
  9. **
  10. **    Version:    1.0        PG    Initial pass
  11. **                1.1        AB    Added prefix file for conditional macros
  12. **                            Changed  ? :  notation to  if else
  13. **
  14. **    Copyright © 1996 Apple Computer, Inc.
  15. **    All rights reserved.
  16. **
  17. **    You may incorporate this sample code into your applications without
  18. **    restriction, though the sample code has been provided "AS IS" and the
  19. **    responsibility for its operation is 100% yours.  However, what you are
  20. **    not permitted to do is to redistribute the source as "DSC Sample Code"
  21. **    after having made changes. If you're going to re-distribute the source,
  22. **    we require that you make it clear in the source that the code was
  23. **    descended from Apple Sample Code, but that you've made changes.
  24. */
  25.  
  26.  
  27. //    Private prefix file
  28. #include "Prefix.h"
  29.  
  30. //    System includes
  31. #include <OSUtils.h>
  32. #include <Traps.h>
  33.  
  34. //    Utility routines
  35. #include "TrapUtils.h"
  36.  
  37.  
  38. // ===============================================================================
  39.  
  40. static pascal UInt16 CountToolboxTraps( void )
  41. {
  42.     static UInt16 trapCount;
  43.     
  44.     if ( !trapCount )
  45.     {
  46.         if ( GetToolTrapAddress( _InitGraf ) == GetToolTrapAddress( 0xAA6E ) )
  47.         {
  48.             trapCount = 0x0200;
  49.         }
  50.         else
  51.         {
  52.             trapCount = 0x0400;
  53.         }
  54.     }
  55.     
  56.     return trapCount;
  57. }
  58.  
  59. // ===============================================================================
  60.  
  61. static pascal TrapType GetTrapType( UInt16 trapWord )
  62. {
  63.     if ( trapWord & 0x0800 )
  64.     {
  65.         return ToolTrap;
  66.     }
  67.     else
  68.     {
  69.         return OSTrap;
  70.     }
  71. }
  72.  
  73. // ===============================================================================
  74.  
  75. pascal Boolean TrapAvailable( UInt16 trapWord )
  76. {
  77.     if ( GetTrapType( trapWord ) == OSTrap )
  78.     {
  79.         return GetToolTrapAddress( _Unimplemented ) != GetOSTrapAddress( trapWord );
  80.     }
  81.     else if ( ( trapWord & 0x07FF ) >= CountToolboxTraps () )
  82.     {
  83.         return false;
  84.     }
  85.     else
  86.     {
  87.         return GetToolTrapAddress( _Unimplemented ) != GetToolTrapAddress ( trapWord );
  88.     }
  89. }
  90.  
  91. // ===============================================================================
  92.  
  93. pascal void * MyGetTrapAddress( UInt16 trapWord )
  94. {
  95.     if ( GetTrapType( trapWord ) == OSTrap )
  96.     {
  97.         return GetOSTrapAddress( trapWord );
  98.     }
  99.     else
  100.     {
  101.         return GetToolTrapAddress( trapWord );
  102.     }
  103. }
  104.  
  105. // ===============================================================================
  106.  
  107. pascal void MySetTrapAddress( UInt16 trapWord, void *newAddr )
  108. {
  109.     if ( GetTrapType( trapWord ) == OSTrap )
  110.     {
  111.         SetOSTrapAddress( newAddr, trapWord );
  112.     }
  113.     else
  114.     {
  115.         SetToolTrapAddress( newAddr, trapWord );
  116.     }
  117. }
  118.  
  119.